<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">上级节点</label>
                <div class="layui-input-block">
                    <ul id="tree" class="dtree" data-id="{$inf.menu_id}" data-value="{$inf.menu_id}"></ul>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">节点名称</label>
                <div class="layui-input-block">
                    <input type="text" name="title" value="{$inf.title}" lay-verify="required" autocomplete="off" placeholder="请输入节点名称"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">节点路径</label>
                <div class="layui-input-block">
                    <input type="text" name="href" value="{$inf.href}" lay-verify="required" autocomplete="off" placeholder="请输入节点路径，例：News/index"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图标</label>
                <div class="layui-input-block">
                    <input type="text" name="icon" value="{$inf.icon}" autocomplete="off" placeholder="请填写图标，例：layui-icon layui-icon-vercode"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-block">
                    <input type="number" name="sort" value="{$inf.sort}" lay-verify="number" value="999" lay-verify="title" autocomplete="off" placeholder="请填写节点排序"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">是否可用</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="status" lay-text="启用|禁用" lay-skin="switch" {eq name="inf['status']" value="1"}checked{/eq}>
                </div>
            </div>
            <input type="hidden" name="id" value="{$inf.id}">
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-modify">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{include file="_Fragment/javascript" /}
<script>
    layui.use(['form', 'jquery', 'dtree'], function() {
        let form = layui.form;
        let dtree = layui.dtree;
        let $ = layui.jquery;

        dtree.render({
            elem: "#tree",
            initLevel: "1",
            method: 'get',
            url: "/menu/getMenuTree",
            select: true,
            selectTips: '请选择上级节点，不选默认一级节点',
        });

        form.on('submit(user-modify)', function(data) {
            let loading = layer.load();
            $.ajax({
                url: '/Menu/modify',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    layer.close(loading);
                    if (result.status == 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.treetable.reload("#power-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>
